﻿using System.IO;
using System.Text.Json.Serialization;

namespace SMCL.Core.Utils.Types
{
    public class LaunchGameInfo
    {
        [JsonInclude]
        public string GameArg { get; set; }
        [JsonInclude]
        public string JavaArg { get; set; }
        [JsonInclude]
        public int JavaVersion { get; set; }
        [JsonInclude]
        public string VersionName { get; set; }
        [JsonInclude]
        public string GameDir { get; set; }
        [JsonInclude]
        public string AssetsDir { get; set; }
        [JsonInclude]
        public string AssetsIndexName { get; set; }
        [JsonInclude]
        public string ClientId { get; set; }
        [JsonInclude]
        public string NativesDir { get; set; }
        [JsonInclude]
        public string ClassPathDir { get; set; }
        [JsonInclude]
        public string GameAddress { get; set; }
        [JsonInclude]
        public string ClassName { get; set; }
        public LaunchGameInfo() { }
        public LaunchGameInfo(GameInfo gameInfo)
        {
            GameArg = gameInfo.GameArg;
            JavaArg = gameInfo.JavaArg;
            JavaVersion = gameInfo.JavaVersion;
            VersionName = gameInfo.VersionName;
            var mcdir = new DirectoryInfo(".minecraft");
            GameDir = mcdir.FullName;
            AssetsDir = mcdir.FullName + "\\assets";
            AssetsIndexName = gameInfo.AssetIndex.Id;
            ClientId = Guid.NewGuid().ToString();
            NativesDir = mcdir.FullName + $"\\versions\\{VersionName}\\native";
            ClassPathDir = mcdir.FullName + "\\libraries";
            GameAddress = new FileInfo($".minecraft\\versions\\{VersionName}\\client.jar").FullName;
            ClassName = gameInfo.MainClass;
        }
        public LaunchGameInfo(GameInfo gameInfo, string dotMinecraftAddress, string gameAddress, string gameJar)
        {
            GameArg = gameInfo.GameArg;
            JavaArg = gameInfo.JavaArg;
            JavaVersion = gameInfo.JavaVersion;
            VersionName = gameInfo.VersionName;
            var mcdir = new DirectoryInfo(dotMinecraftAddress);
            GameDir = mcdir.FullName;
            AssetsDir = mcdir.FullName + "\\assets";
            AssetsIndexName = gameInfo.AssetIndex.Id;
            ClientId = Guid.NewGuid().ToString();
            NativesDir = mcdir.FullName + $"\\versions\\{VersionName}\\native";
            ClassPathDir = mcdir.FullName + "\\libraries";
            GameAddress = gameJar;
            ClassName = gameInfo.MainClass;
        }
    }
}
